from ronglian_sms_sdk import SmsSDK
import json
from django.conf import settings

# 登录容联云查看account SID和auth_token和app_id
# accId = '2c94811c9035ff9f019231782b036634'  # 开发者平台分配的账号ID
# accToken = 'a9800cc374a74d819d33c3cd2d5d9ed5'  # 开发者平台分配的验证码
# appId = '2c94811c9035ff9f019231782c81663b'  # 开发者平台分配的应用ID


def send_message(tid,mobile,datas):
    # 读取配置文件
    rly = settings.RONG_LIAN_YUN
    # 初始化SDK
    sdk = SmsSDK(rly.get('accId'), rly.get('accToken'), rly.get('appId'))
    # 发送短信
    # tid = '1' # 短信模板ID
    # mobile = '1861880000000' # 手机号码
    # datas = ('1234', '5') # 验证码和有效时间
    res = sdk.sendMessage(tid, mobile, datas)
    print(f'发送短息的格式：{res}')
    # 将结果转换为字典
    response = json.loads(res)
    print(f'格式转换后：{response}')
    # 返回短信验证000000成功
    if response.get('statusCode') != '000000':
        raise Exception(response.get('statusMsg'))
    print('短信发送成功')
    return response.get('statusCode') == '000000'
